/**
 * Copyright (C), 2020, 安徽贝慕信息科技有限公司
 * FileName: marvelMetaObjectHandler
 * Author:   Allen
 * Date:     2020/8/12 15:50
 * Description: 统一处理创建时间与更新时间的Handler
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.bim.marvel.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 〈统一处理创建时间与更新时间的Handler〉
 *
 * @author Allen
 * @date 2020/8/12
 * @since 1.0.0
 */
@Component
public class OpenApiMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createdDate", Date.class, new Date());
        this.strictInsertFill(metaObject, "lastUpdated",  Date.class, new Date());
        this.strictInsertFill(metaObject, "deleted", Boolean.class, false);
        this.strictInsertFill(metaObject, "display", Boolean.class, true);
        this.strictInsertFill(metaObject, "disabled", Boolean.class, false);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //因为不置为空，当原updateDate有值时不会覆盖，故而此处先置空
        metaObject.setValue("lastUpdated", null);
        this.strictUpdateFill(metaObject, "lastUpdated", Date.class, new Date());
        //由于目前开放平台审核人员就固定管理员一个用户，故而在此统一处理
        this.strictUpdateFill(metaObject, "reviewOperator", String.class, "开放平台管理员");
        this.strictUpdateFill(metaObject, "reviewDate", Date.class, new Date());
    }
}
